package com.neusoft.SPNursingHome.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.SPNursingHome.po.*;
import com.neusoft.SPNursingHome.po.CareRecordWithAdminAndCareItem;
import com.neusoft.SPNursingHome.service.CareRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/CareRecordController")
public class CareRecordController {
    @Autowired
    private CareRecordService careRecordService;

    // 查看客户护理记录列表
    @GetMapping("/listCareRecord")
    public ResponseBean<List<CareRecord>> listClientCareRecord() {
        return careRecordService.listCareRecord();
    }

    // 根据客户姓名、项目编号、项目名称模糊查询护理记录
    @GetMapping("/getCareRecordByConditions")
    public ResponseBean<List<CareRecord>> getCareRecordByConditions(String clientName, String careItemCode, String careItemName) {
        return careRecordService.getCareRecordByConditions(clientName, careItemCode, careItemName);
    }

    // 管理员选中某个客户可以查看护理记录信息
    // 根据客户id查看客户护理记录列表，并可以根据护理项目名称进行查询
    @GetMapping("/getCareRecordByClientId")
    public ResponseBean<List<CareRecordWithAdminAndCareItem>> getCareRecordByClientId(Integer clientId, String careItemName) {
        return careRecordService.getCareRecordByClientId(clientId, careItemName);
    }

//    // 管理员选中某个客户可以查看护理记录信息
//    // 根据客户id查看客户护理记录列表
//    @GetMapping("/getCareRecordByClientId")
//    public ResponseBean<List<CareRecordWithAdminAndCareItem>> getCareRecordByClientId(Integer clientId) {
//        return careRecordService.getCareRecordByClientId(clientId);
//    }

    // 添加客户护理记录
    @PostMapping("/addCareRecord")
    public ResponseBean<Integer> addCareRecord(@RequestBody CareRecord careRecord) {
        System.out.println("Received care record item id: " + careRecord.getCareItemId());
        return careRecordService.addCareRecord(careRecord);
    }

    // 逻辑移除客户护理记录
    @PostMapping("/deleteCareRecord")
    public ResponseBean<Integer> deleteCareRecord(Integer careRecordId) {
        return careRecordService.deleteCareRecord(careRecordId);
    }
    @GetMapping("/pageByAdminAndFilters")
    public ResponseBean<IPage<CareRecordWithAdminAndCareItemAndClient>> pageByAdminAndFilters(
            @RequestParam Integer adminId,
            @RequestParam(required = false) String careItemName,
            @RequestParam(required = false) String careContent,
            @RequestParam(defaultValue = "1") Long page,
            @RequestParam(defaultValue = "10") Long size
    ) {
        return careRecordService.getPageByAdminAndFilters(
                adminId, careItemName, careContent, page, size
        );
    }

    @GetMapping("/getByRecordId")
    public ResponseBean<CareRecordWithAdminAndCareItemAndClient> getByRecordId(
            @RequestParam Integer careRecordId
    ) {
        return careRecordService.getByRecordId(careRecordId);
    }

}
